//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __SDERR_H_
#define __SDERR_H_

#define _DBGSD 1
#define _SUCSD 1
#define _REGSD 1
#define RETRY 30

// typedef for API Status codes
typedef long SD_API_STATUS;

// DDK api status codes
#define SD_API_STATUS_SUCCESS                          ((SD_API_STATUS)0x00000000L)
#define SD_API_STATUS_PENDING                          ((SD_API_STATUS)0x00000001L)
#define SD_API_STATUS_BUFFER_OVERFLOW                  ((SD_API_STATUS)0xC0000001L)
#define SD_API_STATUS_DEVICE_BUSY                      ((SD_API_STATUS)0xC0000002L)
#define SD_API_STATUS_UNSUCCESSFUL                     ((SD_API_STATUS)0xC0000003L)
#define SD_API_STATUS_NOT_IMPLEMENTED                  ((SD_API_STATUS)0xC0000004L)
#define SD_API_STATUS_ACCESS_VIOLATION                 ((SD_API_STATUS)0xC0000005L)
#define SD_API_STATUS_INVALID_HANDLE                   ((SD_API_STATUS)0xC0000006L)
#define SD_API_STATUS_INVALID_PARAMETER                ((SD_API_STATUS)0xC0000007L)
#define SD_API_STATUS_NO_SUCH_DEVICE                   ((SD_API_STATUS)0xC0000008L)
#define SD_API_STATUS_INVALID_DEVICE_REQUEST           ((SD_API_STATUS)0xC0000009L)
#define SD_API_STATUS_NO_MEMORY                        ((SD_API_STATUS)0xC000000AL)
#define SD_API_STATUS_BUS_DRIVER_NOT_READY             ((SD_API_STATUS)0xC000000BL)
#define SD_API_STATUS_DATA_ERROR                       ((SD_API_STATUS)0xC000000CL)
#define SD_API_STATUS_CRC_ERROR                        ((SD_API_STATUS)0xC000000DL)
#define SD_API_STATUS_INSUFFICIENT_RESOURCES           ((SD_API_STATUS)0xC000000EL)
#define SD_API_STATUS_DEVICE_NOT_CONNECTED             ((SD_API_STATUS)0xC0000010L)
#define SD_API_STATUS_DEVICE_REMOVED                   ((SD_API_STATUS)0xC0000011L)
#define SD_API_STATUS_DEVICE_NOT_RESPONDING            ((SD_API_STATUS)0xC0000012L)
#define SD_API_STATUS_CANCELED                         ((SD_API_STATUS)0xC0000013L)
/* Time out error on card response */
#define SD_API_STATUS_RESPONSE_TIMEOUT                 ((SD_API_STATUS)0xC0000014L)
#define SD_API_STATUS_DATA_TIMEOUT                     ((SD_API_STATUS)0xC0000015L)
#define SD_API_STATUS_DEVICE_RESPONSE_ERROR            ((SD_API_STATUS)0xC0000016L)
#define SD_API_STATUS_DEVICE_UNSUPPORTED               ((SD_API_STATUS)0xC0000017L)
#define SD_API_STATUS_SHUT_DOWN                        ((SD_API_STATUS)0xC0000018L)
/* 198- Check for CRC write error*/
#define SD_API_STATUS_CARD_IS_NOT_RESPONDING           ((SD_API_STATUS)0xC0000019L)
/* 200- Check for CRC write error*/
#define SD_API_STATUS_WD_CRC_ERROR                     ((SD_API_STATUS)0xC000001AL)
/* 200- Check for CRC read error*/
#define SD_API_STATUS_RD_CRC_ERROR                     ((SD_API_STATUS)0xC000001BL)
/* 201- Check for CRC on response*/
#define SD_API_STATUS_RES_CRC_ERROR                    ((SD_API_STATUS)0xC000001CL)
/* 202- CRC error detected on card response */
#define SD_API_STATUS_COM_CRC_ERROR                    ((SD_API_STATUS)0xC000001DL)
/* 228- Address out of range error */
#define SD_API_STATUS_OUT_OF_RANGE                     ((SD_API_STATUS)0xC000001EL)
/* 203- CRC error detected on incoming data block */
#define SD_API_STATUS_DATA_CRC_ERROR                   ((SD_API_STATUS)0xC000001FL)
/* 204- Card is reporting CRC error on outgoing data block. */
#define SD_API_STATUS_DATA_STATUS_CRC_ERROR            ((SD_API_STATUS)0xC0000020L)
/* 205- Card is busy programming */
#define SD_API_STATUS_CARD_IS_BUSY                     ((SD_API_STATUS)0xC0000021L)
/* 206- Card did not complete its initialization and is not ready. */
#define SD_API_STATUS_CARD_IS_NOT_READY                ((SD_API_STATUS)0xC0000022L)
/* 207- Card is reporting CRC error */
#define SD_API_STATUS_COMUNC_CRC_ERROR                 ((SD_API_STATUS)0xC0000023L)
/* 208- Card is reporting illegal command */
#define SD_API_STATUS_COMUNC_ILLEG_COM                 ((SD_API_STATUS)0xC0000024L)
/* 209- Erase parameters error */
#define SD_API_STATUS_ERASE_PARAM                      ((SD_API_STATUS)0xC0000025L)
/* 210- Attempt to write a WP sector */
#define SD_API_STATUS_WP_VIOLATION                     ((SD_API_STATUS)0xC0000026L)
/* 211- MMC card internal error */
#define SD_API_STATUS_ERROR                            ((SD_API_STATUS)0xC0000027L)
/* 212- Attempt to erase WP sector */
#define SD_API_STATUS_WP_ERASE_SKIP                    ((SD_API_STATUS)0xC0000028L)
/* 213- Sector messaligned error */
#define SD_API_STATUS_ADDRESS_ERROR                    ((SD_API_STATUS)0xC0000029L)
/* 214- Card is reporting Read command failed */
#define SD_API_STATUS_CARD_READ_FAILURE                ((SD_API_STATUS)0xC000002AL)
 /* 215- Error detected by the MMC HW driver */
#define SD_API_STATUS_INTERFACE_ERROR                  ((SD_API_STATUS)0xC000002BL)
/* 216- Not support in the current mode */
#define SD_API_STATUS_ILLEGAL_MODE                     ((SD_API_STATUS)0xC000002CL)
/* 217- Card is reporting Address-out-of-range error */
#define SD_API_STATUS_COMMAND_PARAMETER_ERROR          ((SD_API_STATUS)0xC000002DL)
/* 218- Error in the sequence of erase command */
#define SD_API_STATUS_ERASE_SEQ_ERROR                  ((SD_API_STATUS)0xC000002EL)
/* 219- Erase command canceled before execution */
#define SD_API_STATUS_ERASE_RESET                      ((SD_API_STATUS)0xC000002FL)
/* 220- Time out on CRC status for Write */
#define SD_API_STATUS_NO_CRC_STATUS                    ((SD_API_STATUS)0xC0000030L)
/* 221- Overrun */
#define SD_API_STATUS_OVERRUN                          ((SD_API_STATUS)0xC0000031L)
/* 222- Underrun */
#define SD_API_STATUS_UNDERRUN                         ((SD_API_STATUS)0xC0000032L)
/* 223- a) The CID register has been already */
/*        written and can be overwriten. */
/*     b) The read only section of CSD does not */
/*        match the card content. */
/*     c) An attempt to reverse the copy (set */
/*        as original) or permanent WP bits was made. */
#define SD_API_STATUS_CIDCSD_OVERWRITE                 ((SD_API_STATUS)0xC0000033L)
/* 224- The command has been executed without */
/*     using the internal ECC. */
#define SD_API_STATUS_CARD_ECC_DISABLED                ((SD_API_STATUS)0xC0000034L)
/* 225- Corresponds to buffer empty signalling on the bus*/
#define SD_API_STATUS_READ_FOR_DATA                    ((SD_API_STATUS)0xC0000035L)
/* 226- Data Length more then 512 bytes. */
#define SD_API_STATUS_DATA_LENGTH_ERROR                ((SD_API_STATUS)0xC0000036L)
/* 227- Time out recive data (B0 for controller) */
#define SD_API_STATUS_TIME_OUT_RCVD                    ((SD_API_STATUS)0xC0000037L)
/* 229- Internal Card ECC failed */
#define SD_API_STATUS_CARD_ECC_FAILED                  ((SD_API_STATUS)0xC0000038L)
/* 230- Card is locked by host */
#define SD_API_STATUS_CARD_IS_LOCKED                   ((SD_API_STATUS)0xC0000039L)
/* 231- Lock/unlock card failed or access to locked card */
#define SD_API_STATUS_LOCK_UNLOCK_FAILED               ((SD_API_STATUS)0xC000003AL)
/* Flash Error */
#define SD_API_STATUS_FLASH_ERR                        ((SD_API_STATUS)0xC000003BL)

// macro to test for success
#define SD_API_SUCCESS(Status) ((SD_API_STATUS)(Status) == 0)
#define SD_API_FAILED(Status) ((SD_API_STATUS)(Status) != 0)
// macro to test for success where a SD_API_STATUS_TIMEOUT is okay
#define SD_API_SUCCESS_RESPONSE_TIMEOUT_OK(Status) (((SD_API_STATUS)(Status) >= 0) || (SD_API_STATUS_RESPONSE_TIMEOUT == (SD_API_STATUS)(Status)))
// macro to test explicitly for time out
#define SD_API_RESPONSE_TIMEOUT(Status) (SD_API_STATUS_RESPONSE_TIMEOUT == (SD_API_STATUS)(Status))

#endif//__SDERR_H_

